package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVO;
import com.xuecheng.content.common.util.UAASecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService  courseTeacherService;

    @GetMapping("courseTeacher/list/{courseId}")
    public List<CourseTeacherDTO> queryTeacherList(@PathVariable Long courseId) {

        Long companyId = UAASecurityUtil.getCompanyId();

        List<CourseTeacherDTO> dtos = courseTeacherService.queryTeacherList(courseId, companyId);

        return dtos;
    }



    @PostMapping("courseTeacher")
    public CourseTeacherDTO createOrModifyTeacher(@RequestBody CourseTeacherVO vo) {

        Long companyId = UAASecurityUtil.getCompanyId();

        CourseTeacherDTO dto = CourseTeacherConvert.INSTANCE.vo2dto(vo);

        CourseTeacherDTO result = courseTeacherService.createOrModifyTeacher(dto, companyId);

        return result;
    }

    @DeleteMapping("courseTeacher/course/{courseId}/{courseTeacherId}")
    public void removeTeacher(@PathVariable Long courseId,@PathVariable Long courseTeacherId) {

        Long companyId = UAASecurityUtil.getCompanyId();

        courseTeacherService.removeTeacher(courseId,courseTeacherId, companyId);

    }


}
